import mysql.connector
import random

config = {
    'host': "1.1.1.1",
    'user': 'root',
    'password': '********',
    'database': 'school_db',
    'charset': 'utf8mb4',
    'collation': 'utf8mb4_unicode_ci',
    'port': 3306
}
conn = mysql.connector.connect(**config)
cursor = conn.cursor()

cursor.execute("SELECT id FROM students")
students = cursor.fetchall()

classes = ['6年级1班', '6年级2班', '6年级3班', '6年级4班', '6年级5班', '6年级6班']
for student in students:
    new_class = random.choice(classes)
    cursor.execute("UPDATE students SET class=%s WHERE id=%s", (new_class, student[0]))

conn.commit()
cursor.close()
conn.close()